package Operation;

import Book.Library;

import java.util.Scanner;

public class BorrowBook implements IOperation{
    @Override
    public void work(Library library) {
        System.out.println("借书");
        if(library.getSize() == 0){
            System.out.println("书架中没书");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要借的书的名字：");
        String name = scanner.nextLine();
        for (int i = 0; i < library.getSize(); i++) {
            if(library.getBook(i).getName().equals(name)){
                if(library.getBook(i).isSituation()){
                    System.out.println("该书已借出");
                    return;
                }else {
                    System.out.println("借书成功 —— 《" + name + "》");
                    library.getBook(i).setSituation(true);
                    return;
                }
            }
        }
    }
}
